package com.yuyou.fn.tas.pusher.handler;

import com.alibaba.fastjson.JSONArray;
import com.yuyou.fn.common.database.event.EventHandler;
import com.yuyou.fn.common.database.event.IEventHandler;
import com.yuyou.fn.educational.entity.Student;
import com.yuyou.fn.educational.entity.StudentReg;
import com.yuyou.fn.tas.pusher.service.IDataPushService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ExecutionException;


@EventHandler(tables = "yyfn.student")
@Component
public class StudentPusher implements IEventHandler {

    @Resource
    private IDataPushService dataPushService;


    @Override
    public void insert(String tableName, JSONArray rowList) {
        try {
            handleStudent(rowList);
        }catch (ExecutionException e){

        }

    }

    @Override
    public void update(String tableName, JSONArray rowList, Set<String> updateColumns)  {
        try {
            handleStudent(rowList);
        }catch (ExecutionException e){

        }
    }

    @Override
    public void delete(String tableName, JSONArray rowList) {

    }

    private void handleStudent(JSONArray rowList) throws ExecutionException {

        List<Student> students = rowList.toJavaList(Student.class);
        dataPushService.pushStudent(students);

    }
}
